package org.bhf.i18n;

/**
 * Exception that carries a list of i18n Messages
 */
public class MessagesException extends Exception
{
    private static final long serialVersionUID = 1L;

    final Messages messages;

    /**
     * Create a <code>MessagesException</code> for a single <code>Message</code>.
     *
     * @param message Must not be <code>null</code>
     * @param exception The class name becomes the type fields of the JSON exception. May be <code>null</code>
     */
    public MessagesException( final Message message, final Throwable exception )
    {
        super( exception );
        if( message == null )
            throw new IllegalArgumentException( "messages == null" );

        this.messages = new Messages();
        this.messages.addMessage( message );
    }

    /**
     * Create a <code>MessagesException</code> for a <code>Messages</code> set.
     *
     * @param messages Must not be <code>null</code>
     * @param exception The class name becomes the type fields of the JSON exception. May be <code>null</code>
     */
    public MessagesException( final Messages messages, final Throwable exception )
    {
        super( exception );
        if( messages == null )
            throw new IllegalArgumentException( "messages == null" );

        this.messages = messages;
    }

    public Messages getMessages()
    {
        return messages;
    }
}